{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "af2b2649",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "---------【HAPPY DRINK TIME】---------\n",
      "    ['草莓碎碎冰', 19]\n",
      "    ['芝芝霉霉', 18]\n",
      "    ['西瓜椰椰', 18]\n",
      "    ['芝芝绿妍', 15]\n",
      "    ['多肉葡萄', 20]\n",
      "    \n",
      "请输入您的余额：55\n",
      "---------【商品列表】---------\n",
      "商品编号：0，商品名称：草莓碎碎冰，商品的价格：19 元\n",
      "商品编号：1，商品名称：芝芝霉霉，商品的价格：18 元\n",
      "商品编号：2，商品名称：西瓜椰椰，商品的价格：18 元\n",
      "商品编号：3，商品名称：芝芝绿妍，商品的价格：15 元\n",
      "商品编号：4，商品名称：多肉葡萄，商品的价格：20 元\n",
      "请输入正确的商品编号(输入“q”可以退出购买)：1\n",
      "【芝芝霉霉】 已经添加到您的购物车，您的余额还有 【37】 元\n",
      "---------【商品列表】---------\n",
      "商品编号：0，商品名称：草莓碎碎冰，商品的价格：19 元\n",
      "商品编号：1，商品名称：芝芝霉霉，商品的价格：18 元\n",
      "商品编号：2，商品名称：西瓜椰椰，商品的价格：18 元\n",
      "商品编号：3，商品名称：芝芝绿妍，商品的价格：15 元\n",
      "商品编号：4，商品名称：多肉葡萄，商品的价格：20 元\n",
      "请输入正确的商品编号(输入“q”可以退出购买)：q\n",
      "----------------- \n",
      " 您的购物车：[['芝芝霉霉', 18]]  \n",
      " 您的余额还有：37 元\n"
     ]
    }
   ],
   "source": [
    "\n",
    "goods_list = [\n",
    "    # 商品1 商品名称，商品价格，商品编号...\n",
    "    # 商品模板：[商品名称，商品名称]\n",
    "  [\"草莓碎碎冰\",19],\n",
    "    [\"芝芝霉霉\",18],\n",
    "    [\"西瓜椰椰\",18],\n",
    "    [\"芝芝绿妍\",15],\n",
    "    [\"多肉葡萄\",20],\n",
    "]\n",
    "\n",
    "info = '''---------【HAPPY DRINK TIME】---------\n",
    "    %s\n",
    "    %s\n",
    "    %s\n",
    "    %s\n",
    "    %s\n",
    "    ''' % (goods_list[0], goods_list[1], goods_list[2], goods_list[3], goods_list[4])\n",
    "print(info)\n",
    "\n",
    "user_shopping_car = [] # append 可以新增列表\n",
    "\n",
    "# 用户输入： input用户余额宝\n",
    "Alipay = int(input(\"请输入您的余额：\"))\n",
    "\n",
    "# 打印商品列表 （规范打印，样式是先写的，然后再输入数据）\n",
    "## 方法一：info输出打印\n",
    "\n",
    "##方法二：定模板打印：\n",
    "\n",
    "# 先设计模板样式： 商品编号：xx，商品名称：xx，商品的价格：xx 元\n",
    "while True:\n",
    "        # for i in range(len(goods_list)):\n",
    "        # print(info)\n",
    "        #break\n",
    "    \n",
    "    print(\"---------【商品列表】---------\")\n",
    "    for i in range(len(goods_list)):\n",
    "        # print(\"商品编号：%s，商品名称：%s，商品的价格：%d 元\"%(0,goods_list[0][0],goods_list[0][1]))\n",
    "        print(\"商品编号：%s，商品名称：%s，商品的价格：%d 元\"%(i,goods_list[i][0],goods_list[i][1]))\n",
    "\n",
    "\n",
    "    # 2、让用户输入商品编号进行商品的购买。\n",
    "    choice = input(\"请输入正确的商品编号(输入“q”可以退出购买)：\") # 用户输入可能不是数值，也可能是\n",
    "    if choice.isdigit():\n",
    "        # 用int转换数据类型为数值\n",
    "        choice = int(choice)\n",
    "        # 是正确的编号\n",
    "        if choice < len(goods_list):  # 商品的信息：goods_list[choice] ，商品名称：goods_list[choice][0]  商品价格:goods_list[choice][1]\n",
    "            # 1. 看一看用户钱够不够； Alipay VS goods_list[choice][1]\n",
    "            if Alipay < goods_list[choice][1]:\n",
    "                print(\"您的余额不够，请更换支付方式\")\n",
    "            # 2. 如果够的话，赶紧扣钱！把商品加到购物车\n",
    "            else:\n",
    "                Alipay = Alipay - goods_list[choice][1]\n",
    "                user_shopping_car.append(goods_list[choice])\n",
    "                # 提示用户：本次购买成功\n",
    "                print(\"【%s】 已经添加到您的购物车，您的余额还有 【%d】 元\"%(goods_list[choice][0],Alipay))\n",
    "\n",
    "        # 不是正确的编号\n",
    "        else:\n",
    "            print(\"您输入的商品不存在，请输入正确的编号\")\n",
    "    elif choice == \"q\":\n",
    "        print(\"-----------------\",'\\n',\"您的购物车：%s \"%(user_shopping_car),'\\n',\"您的余额还有：%d 元\"%(Alipay))\n",
    "        break\n",
    "        \n",
    "        # 两种情况：\n",
    "        # 1. 按照我们的要求输入的文本，例如：输入q表示quit退出的意思\n",
    "        \n",
    "        # 2. 输入的不符合我们的要求的文本\n",
    "    else:\n",
    "         print(\"请输入正确的商品编号！！或者输入“q”退出\")\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4c8f71e3",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
